<template>
  <view>
    <view class="search-box">
       <my-search @click="gotoSearch"  ></my-search>
    </view>
    
    <!-- <button @click="ge">点击</button> -->
    <!-- ///轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator class="swiper-item" :url="'/subpackges/goods_detail/goods_detail?goods_detail='+item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- ///分类导航区域 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(item,index) in navList" :key="index" @click="onclickNavItem(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    <!-- 楼梯区域 -->
    <view class="floor-list" v-for="(item,index) in floorList" :key="index">
      <image class="floor-title" :src="item.floor_title.image_src"></image>
      <view class="floor-img-box">
        <navigator class="leftBox" :url="item.product_list[0].url">
        
          <image :src="item.product_list[0].image_src" mode=""
            :style="{width: item.product_list[0].image_width + 'rpx'}">
          </image>
        </navigator>
        
        <view class="rightBox">
          <navigator class="rightBox-item" v-for="(img,i2) in item.product_list" :key="i2" :url="img.url"  >
            <image :src="img.image_src" mode="widthFix" :style="{width: img.image_width + 'rpx'}" v-if=" i2 !== 0 ">
            </image>
          </navigator>
        </view>
      </view>


    </view>

  </view>
</template>

<script>
  import tabbarNumber from "@/maxins/tabbar.js"
  export default {
       mixins:[tabbarNumber],
    data() {
      return {
        swiperList: [],
        navList: [],
        floorList: []
      };
    },
    onLoad() {
      // 2. 在小程序页面刚加载的时候，调用获取轮播图数据的方法

      this.getSwiperList()
      this.getnavList()
      this.getFloorList()
    },
    methods: {

      async getSwiperList() {
        // 3.1 发起请求
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        }
        this.swiperList = res.message
      },
      async getnavList() {
        // 3.1 发起请求
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        }
        this.navList = res.message

      },
      async getFloorList() {
        // 3.1 发起请求
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) {
          return uni.$showMsg()
        }

        res.message.forEach(floor => {
          floor.product_list.forEach(prod => {
            prod.url = '/subpackges/goods_list/goods_list?' +
              prod.navigator_url.split('?')[1]
          })
        })

        this.floorList = res.message

      },
      onclickNavItem(item) {
        if (item.name == '分类') {
          uni.switchTab({
            url: '/pages/cate/cate'
          })
        }
      }, gotoSearch(){
        uni.navigateTo({
          url:'/subpackges/search/search'
        })
      },
      
      ge() {

        console.log(this.floorList)
      }
    },
  }
</script>

<style lang="scss">
  .search-box{
    position: sticky;
    top:0;
    z-index: 999;
  }
  swiper {
    height: 330rpx;
    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .nav-list {
    display: flex;
    justify-content: space-around;

    .nav-item image {
      margin: 15rpx;
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-img-box {
    display: flex;

    .leftBox {
      padding-left: 10rpx;
    }

    .rightBox {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;

    }
  }
  .floor-title {
    height: 60rpx;
    width: 100%;
  }
</style>